import { getMeberMessageAPI, postLoginAPI } from "@/api/login";
import {LoginParam, Meber } from "@/api/type/login";
import { defineStore } from "pinia";
import { ref } from "vue";

export const  useUserStore=defineStore('user', ()=>{
  let dialogTableVisible=ref<boolean>(false)
  let MeberInfo=ref<Meber>()
  let userInfo=JSON.parse(sessionStorage.getItem('TOKEN_KEY') as string)|| {}
  const changeDialog=(value:boolean)=>{
    dialogTableVisible.value=value
  }
  const getMeber=async()=>{
    const res=await getMeberMessageAPI()
    MeberInfo.value=res.data
    console.log(res);
    
  }
  const getToken=async(form:LoginParam)=>{
    const res=await postLoginAPI(form)
    userInfo.value=res.data
    sessionStorage.setItem('TOKEN_KEY',JSON.stringify(res.data))
  }
  const removeToken=()=>{
    sessionStorage.removeItem('TOKEN_KEY')
  }
  return {
    dialogTableVisible,
    changeDialog,
    removeToken,
    getToken,
    getMeber,
    MeberInfo,
    userInfo
  }
})